package com.zlsoft.sbsm.test;

public class HiArray {
    public static void printarray(int[][] as) {
        for (int i = 0; i < as.length; i++) {
            for (int j = 0; j < as[i].length; j++) {
                System.out.print(as[i][j]+" ");
            }
            System.out.println();
        }
    }



    public static void main(String[] args) {
        int[][] as={
                {59,28,73,64,44,66,68,99,26},
                {57,86,71},
                {81,93,61,22,33,87,92}
        };

        System.out.println("原始成绩");
        printarray(as);
        maxAndAve(as);
    }

    public static void maxAndAve(int[][] as) {
        System.out.println("排序每组成绩：");
        for (int i = 0; i < as.length; i++) {

            sort(as[i]);
        }
       printarray(as);
        System.out.println("每组最大值：");
        for (int i = 0; i < as.length; i++) {
            System.out.println(as[i][as[i].length-1]);
        }
        System.out.println("每组平均分：");
        for (int i = 0; i < as.length; i++) {
            double sum=0;
            for (int j = 0; j < as[i].length; j++) {
                sum += as[i][j];
            }
            System.out.println("No."+(i+1)+"组平均分："+sum/as[i].length);
        }

    }

    private static void sort(int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            int k=i;
            for (int j = i+1; j < a.length; j++) {
                if(a[k]>a[j])
                    k=j;
            }
            int t=0;
            if (k != i) {
                t = a[k];
                a[k]=a[i];
                a[i]=t;
            }
        }
    }
}
